package com.space.rabbitmq.sender;

import com.space.rabbitmq.config.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 消息发送 生产者
 *
 * @author zhanglei
 */
@Slf4j
@Component
public class FirstSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     * @param uuid
     */
    public void send(String uuid) {
        CorrelationData correlationId = new CorrelationData(uuid);
        /**
         * RabbitMqConfig.EXCHANGE  指定消息交换机
         * RabbitMqConfig.ROUTINGKEY2  指定队列key2
         */
        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ONE, RabbitMqConfig.ROUTINGKEY1, "111", correlationId);

        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ONE, RabbitMqConfig.ROUTINGKEY2, "222", correlationId);

        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ONE, RabbitMqConfig.ROUTINGKEY3, "333", correlationId);

        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_TWO, RabbitMqConfig.ROUTINGKEY4, "444", correlationId);

        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_TWO, RabbitMqConfig.ROUTINGKEY5, "555", correlationId);

        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_TWO, RabbitMqConfig.ROUTINGKEY6, "666", correlationId);
    }
}
